<?php
$title = '我的订单';
/** @var array $orders */
/** @var string|null $filterStatus */
require __DIR__ . '/../partials/head.php';
require __DIR__ . '/../partials/nav.php';
?>
<section class="section">
    <div class="app-container" style="display:flex;flex-direction:column;gap:24px;">
        <div class="card" style="gap:18px;">
            <div style="display:flex;justify-content:space-between;align-items:center;">
                <h2 style="margin:0;">订单列表</h2>
                <form method="get" action="/orders" style="display:flex;gap:12px;align-items:center;">
                    <label style="color:var(--text-secondary);">状态筛选</label>
                    <select name="status">
                        <option value="">全部</option>
                        <?php foreach (['sent','filled','partial','rejected','error'] as $status): ?>
                            <option value="<?= $status ?>" <?= $filterStatus === $status ? 'selected' : '' ?>><?= strtoupper($status) ?></option>
                        <?php endforeach; ?>
                    </select>
                    <button class="btn-ghost btn" type="submit">应用</button>
                </form>
            </div>
            <?php if (empty($orders)): ?>
                <div class="empty-state">
                    <img src="/assets/img/empty/orders.svg" alt="暂无订单">
                    <p>暂无订单记录，等待策略触发。</p>
                </div>
            <?php else: ?>
                <table class="table">
                    <thead>
                    <tr>
                        <th>时间</th>
                        <th>脚本</th>
                        <th>方向</th>
                        <th>数量</th>
                        <th>价格</th>
                        <th>状态</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?php foreach ($orders as $order): ?>
                        <tr title="<?= htmlspecialchars($order['error'] ?? '') ?>">
                            <td><?= \Frontend\Helpers\Format::datetime($order['created_at'] ?? '') ?></td>
                            <td><?= htmlspecialchars((string)($order['symbol'] ?? '-')) ?></td>
                            <td><?= htmlspecialchars((string)($order['side'] ?? '-')) ?></td>
                            <td><?= htmlspecialchars((string)($order['qty'] ?? '-')) ?></td>
                            <td><?= htmlspecialchars((string)($order['price'] ?? '-')) ?></td>
                            <td><?= htmlspecialchars((string)($order['status'] ?? '-')) ?></td>
                        </tr>
                    <?php endforeach; ?>
                    </tbody>
                </table>
            <?php endif; ?>
        </div>
    </div>
</section>
<?php require __DIR__ . '/../partials/footer.php'; ?>
